/*
 * =====================================================================================
 *
 *       Filename:  communiSys_1018.cc
 *
 *    Description:  choose the manufactures so that B/P is max
 *
 *        Version:  1.0
 *
 *        Created:  09/17/2012 07:04:12 PM
 * =====================================================================================
 */
#include	<stdio.h>
#include	<limits.h>
typedef unsigned long long ull;
unsigned long bandwidth[104][104];
unsigned long price[104][104];
int deviceNo, deviceMacs[104];
bool findASolution = false;
unsigned long long bestB, bestP;
unsigned long long currB, currP;

void searchASolution(int idx)
{
    if (idx >= deviceNo) {
        if (!findASolution)
            findASolution = true;
        bestB = currB;
        bestP = currP;
    }
    for (int k = 0; k < deviceMacs[idx]; ++k) {
        if (bandwidth[idx][k] < currB) {
            unsigned long bakCurrB = currB;
            if (findASolution) {
                if (bandwidth[idx][k] * bestP < bestB * (currP+price[idx][k]))
                    continue;
            }
            currP += price[idx][k];
            currB = bandwidth[idx][k];
            searchASolution(idx+1);
            currP -= price[idx][k];
            currB = bakCurrB;
        } else {
            if (findASolution) {
                if (currB * bestP < bestB * (currP+price[idx][k]))
                    continue;
            }
            currP += price[idx][k];
            searchASolution(idx+1);
            currP -= price[idx][k];
        }
    }
}

int main(int argc, char *argv[])
{
    int T;
    while (scanf("%d", &T) == 1)
    {
        while (T--) {
            scanf("%d", &deviceNo);
            for (int i = 0; i < deviceNo; ++i) {
                scanf("%d", &deviceMacs[i]);
                for (int k = 0; k < deviceMacs[i]; ++k)
                    scanf("%lu%lu", &bandwidth[i][k], &price[i][k]);
            }
            currB = ULONG_MAX; currP = 0;
            findASolution = false;
            searchASolution(0);
            double ans = 1.0 * bestB / bestP;
            printf ( "%.3f\n", ans);
        }
    }
}
